$(function () {
    $("#page").load('/html/page.html');
    // findAll();
});
layui.use("layer");

function findAll() {
    let data = {
        roleName: $("#roleName").val(),
        crateTime: $("#createTime").val(),
        pageNum: $("#pageNum").val(),
        pageSize: $("#pageSize").val()
    };
    let result = myAjax('/role/findAll', 'post', data);
    $("#pageCount").html(result.data.number);
    if (result.code === 200) {
        showRoleList(result.data.list);
    } else {
        layer.msg("查询失败，请稍后再试！！！")
    }
}

function showRoleList(data) {
    let html = "";
    for (let i = 0; i < data.length; i++) {
        if (data[i].status===1){
            data[i].status="是";
        }else {
            data[i].status= "否"
        }
        html += '<tr>' +
            '  <td><input type="checkbox" name="isCheck" value="' + data[i].id + '">' + data[i].id + '</td>' +
            '  <td>' + data[i].roleName + '</td>' +
            '  <td>' + data[i].description + '</td>' +
            '  <td>' + data[i].status + '</td>' +
            '  <td>' + data[i].createTime + '</td>' +
            '  <td><input style="border-radius: 5px;width:80px;background-color: #009E94" type="button" value="编辑" ' +
            'onclick="editRole(' + data[i].id + ')">' +
            '      <input style="border-radius: 5px;width:80px;background-color: #dc7632" ' +
            'type="button" value="权限分配" onclick="compareper(' + data[i].id + ')">' +
            '      <input style="border-radius: 5px;width:80px;background-color: #229ad2" ' +
            'type="button" value="分配用户" onclick="compareMana(' + data[i].id + ')">' +
            '</td></tr>';
    }
    $("#findAll").html(html);
}
//编辑
function editRole(id) {
//需要弹出界面
    sessionStorage.setItem("roleId",id);
    //弹出一个页面层
    layer.open({
        type: 2,
        anim:3,
        title:'角色编辑',
        area: ['600px', '500px'],
        shadeClose: true, //点击遮罩关闭
        content: ['/html/permission/roleEdit.html','no'],
    })
}
//给角色分配权限
function compareper(id) {
//需要一个弹窗界面
    sessionStorage.setItem("roleId",id);
    //弹出一个页面层
    layer.open({
        type: 2,
        anim:3,
        title:'角色--权限分配',
        area: ['600px', '500px'],
        shadeClose: true, //点击遮罩关闭
        content: ['/html/permission/roleComparePes.html','no'],
    })
}
//给角色分配用户
function compareMana(id) {

}
function addRole() {
    //弹出一个页面层
    layer.open({
        type: 2,
        anim:3,
        title:'添加角色',
        area: ['600px', '500px'],
        shadeClose: true, //点击遮罩关闭
        content: ['/html/permission/roleAdd.html','no'],
    })
}